package com.cip.master.dao.impl;

import java.util.List;

import com.cip.admin.dao.impl.CipHibernateDAOSupport;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.cip.master.dao.SubjectDAO;
import com.cip.master.model.Subject;

public class SubjectDAOImpl extends CipHibernateDAOSupport implements SubjectDAO{
	
	public List<Subject> getAllSubjectList() throws Exception {
		HibernateTemplate hibernateTemplate = getCipHibernateTemplate();		
	    List<Subject> subjectList = hibernateTemplate.loadAll(Subject.class);
		return subjectList;
	}

	public Subject getSubjectById(int id) throws Exception {
		HibernateTemplate hibernateTemplate = getHibernateTemplate();
		 return hibernateTemplate.get(Subject.class, id);
	}

	public Subject saveOrUpdateSubject(Subject subject) throws Exception {
		getHibernateTemplate().saveOrUpdate(subject);
		return subject;
	}

	public Subject editSubject(Subject subject) throws Exception {
		getHibernateTemplate().update(subject); 
		return subject;
	}
	
	public Subject getSubjectByCode(String code) throws Exception{
		String query="select subject from Subject as subject where subject.code='"+code+"'";
		return (Subject)getCipHibernateTemplate().find(query).get(0);
	}
	
	public Subject getSubjectByName(String subjectName) throws Exception{
		String query="select subject from Subject as subject where subject.subjectName='"+subjectName+"'";
		return (Subject)getCipHibernateTemplate().find(query).get(0);
	}

}
